<script setup lang="ts">
import { useAppStore, useUserStore } from './stores'
import { onMounted } from 'vue'

// 初始化状态
const appStore = useAppStore()
const userStore = useUserStore()

// 在组件挂载后初始化状态
onMounted(() => {
  appStore.init()
  userStore.init()
})
</script>

<template>
  <div class="min-h-screen" :class="{ 'bg-gray-100': appStore.theme === 'light', 'bg-gray-800 text-white': appStore.theme === 'dark' }">
    <!-- 路由视图 -->
    <main class="container mx-auto p-4">
      <router-view v-slot="{ Component }">
        <transition name="fade" mode="out-in">
          <keep-alive>
            <component :is="Component" />
          </keep-alive>
        </transition>
      </router-view>
    </main>
  </div>
</template>

<style>
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>
